package Thread;

/**
 * Created with Intellij IDEA.
 * Description:
 * User: 86135
 * Date: 2023-10-15
 * Time: 11:09
 */
public class Sequential_Multithreaded {
    private static int count = 0;
    private static final Object lock = new Object();

    public static void main(String[] args) throws InterruptedException {

        Thread t1 = new Thread(()->{
            while(count<10){
                synchronized (lock){
                    if(count%3 == 0){
                        System.out.print("A");
                        count++;
                    }
                }
            }
        });

        Thread t2 = new Thread(()->{
            while(count<10){
                synchronized (lock){
                    if(count%3 == 1){
                        System.out.print("B");
                        count++;
                    }
                }
            }

        });

        Thread t3 = new Thread(()->{
            while(count<10){
                synchronized (lock){
                    if(count%3 == 2){
                        System.out.print("C");
                        count++;
                    }
                }
            }

        });
        t1.start();
        t2.start();
        t3.start();

        t1.join();
        t2.join();
        t3.join();




    }
}
